package com.burgeon.backend.Rest.User.vipType;
/**
 * 按条件获取用户信息
 */

import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.entity.RetailRecordItem;
import com.burgeon.backend.entity.User;
import com.burgeon.backend.service.ActivityService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.regex.Pattern;

public class FindVipType extends RESTBase {
    private final static String RANGE = "50";//分页数量
    private final static Log logger = LogFactory.getLog(FindVipType.class);

    private String ip;
    private String account;
    private String password;

    public FindVipType(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public ArrayList<String> getData() throws Exception {
        String url = "http://"+ip+"/servlets/binserv/Rest";

        String str = RESULT(Data(),url);
        System.err.println(str);
        String count = new JSONArray(str).getJSONObject(0).getString("count");
        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");
        ArrayList<String> data = new ArrayList();
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONArray array = jsonArray.getJSONArray(i);

            data.add(array.getString(0));

        }
        logger.info(data);
        return data;
    }

    private MultiValueMap Data() {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段
        columns.add("NAME");


        params.put("columns", columns);
        params.put("table", "C_VIPTYPE");//表名

        params.put("range",RANGE);
        params.put("count","true");

//        HashMap paramss = new HashMap();
//        String ac = "'=" + "uu" + "'";
//        paramss.put("column", "M_RETAIL_ID");
//        paramss.put("condition", ac);
//        params.put("params", paramss);
        return DATA("Query", params,account,password);
    }

    public static void main(String[] args) {
        FindVipType g = new FindVipType("59.110.28.94:90","nea@burgeon.com.cn","burgeon55321");
        try {
            System.err.println(g.getData());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
